package com.mindao.app.es.rest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mindao.app.common.spring.controller.BaseController;
import com.mindao.app.es.model.EsTeam;
import com.mindao.app.weixin.utils.WxmpConfUtils;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：用户注册和登录
/*
/* 创 建 人：李国才
/* 创建时间：2016年7月15日 下午4:27:19 	
 **/
@Controller
@RequestMapping("/es/esuserrest")
public class EsUserRestController extends BaseController<EsTeam> {
	/**
	 * 微信服务号被拦截器拦截后的跳转地址，会把open保存到Session，并
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @param code
	 * @param state
	 * @return
	 * @throws Exception
	 */
	@RequestMapping   
	public String registerWxmpAuth(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,String code,String state) throws Exception {
		String openid= WxmpConfUtils.getWeixinUserInfo(session, code, state);
		if (openid!=null){
			return super.redirectWithNewParam(request, response, "WxmpAuth", "", "uuid="+state);
		}else{
			return super.rtnGlobalBusinessErrorWithMsg(request, response, session, rhs, "openid is null");
		}
	}
	/**
	 * 通过微信服务号报名的地址
	 * 如果Session没有openid,会被使用拦截器拦截
	 * 如果Session有openid,会被转向到eventEnroll
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception
	 */
	@RequestMapping  
	public String registerWxmp(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,String uuid) throws Exception {
		return super.redirectWithNewParam(request, response, "Wxmp", "","uuid="+uuid);
	}
	
	/**
	 * 通过微信服务号报名的地址
	 * 如果Session没有openid,会被使用拦截器拦截
	 * 如果Session有openid,会被转向到eventEnroll
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 * @throws Exception
	 */
	@RequestMapping  
	public String register(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,String uuid) throws Exception {
		return super.rtnDefault(request, response, session, rhs);
	}
}
